package com.scujj.cs6.controller;

import com.scujj.cs6.annotation.AuthCheck;
import com.scujj.cs6.common.Result;
import com.scujj.cs6.service.UserLikeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户点赞接口", description = "用户点赞相关 API")
@RestController
@RequestMapping("/likes")
@Validated
public class    UserLikeController {
    @Autowired
    private UserLikeService userLikeService;

    @Operation(summary = "点赞回答", description = "对回答点赞")
    @PostMapping("/{id}")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    public Result<Void> likeAnswer(@Parameter(name = "id" , description = "回答ID", required = true , in = ParameterIn.PATH) @PathVariable Long id, HttpServletRequest request) {
        userLikeService.likeAnswer(id, request);
        return Result.success();
    }

    @Operation(summary = "取消点赞问题", description = "取消点赞问题")
    @DeleteMapping("/{id}")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    public Result<Void> cancelLikeAnswer(@Parameter(name = "id" , description = "回答ID", required = true , in = ParameterIn.PATH) @PathVariable Long id, HttpServletRequest request) {
        userLikeService.cancelLikeAnswer(id, request);
        return Result.success();
    }
}